﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoLoL.Entities;

namespace AutoLoL.Logic.Masteries
{
    public class MasteryValidator
    {
        public static bool IsValid(string masteries)
        {
            int index = 0;
            foreach (MasteryTree masteryTree in MasteryRepository.GetEditor().MasteryTrees)
            {
                foreach (Mastery mastery in masteryTree.Masteries)
                {
                    // Too few entries in input
                    if (index == masteries.Length)
                    {
                        return false;
                    }

                    int value = 0;

                    // Invalid value
                    if (!int.TryParse(masteries.Substring(index, 1), out value))
                    {
                        return false;
                    }

                    // Value too big
                    if (value > mastery.MaximumRank)
                    {
                        return false;
                    }

                    index++;
                }
            }

            // Too many entries in input
            if (index < masteries.Length)
            {
                return false;
            }

            return true;
        }
    }
}
